﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProTrack.Api.Helper;
using ProTrack.Dto;
using ProTrack.Entity;
using ProTrack.IServices.Integrated;
using ProTrack.IServices.MasterData;
using ProTrack.IServices.OA;
using ProTrack.IServices.Product;
using ProTrack.IServices.ProductProcess;
using ProTrack.IServices.StoreHouse;
using ProTrack.IServices.Works;
using ProTrack.Services.Works;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ProTrack.Api.Controllers
{

    /// <summary>
    /// 综合请求服务接口
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class IntegratedController : ControllerBase
    {
        public IntegratedController(LogHelper LogHelper,
            IModelServices modelServices,
            ISpecServices specServices,
            IVendorServices vendorServices,
            IUnitMeasureServices unitMeasureServices,
            IWorkshopServices workshopServices,
            IProProcess proProcess,
            IClientServices clientServices,
            IEmployees employeesServices,
            IWarehouseServices warehouseServices
            )
        {
            this.LogHelper = LogHelper;
            ModelServices = modelServices;
            SpecServices = specServices;
            VendorServices = vendorServices;
            UnitMeasureServices = unitMeasureServices;
            WorkshopServices = workshopServices;
            ProProcess = proProcess;
            ClientServices = clientServices;
            EmployeesServices = employeesServices;
            WarehouseServices = warehouseServices;
        }

        public LogHelper LogHelper { get; }
        public IModelServices ModelServices { get; }
        public ISpecServices SpecServices { get; }
        public IVendorServices VendorServices { get; }
        public IUnitMeasureServices UnitMeasureServices { get; }
        public IWorkshopServices WorkshopServices { get; }
        public IProProcess ProProcess { get; }
        public IClientServices ClientServices { get; }
        public IEmployees EmployeesServices { get; }
        public IWarehouseServices WarehouseServices { get; }




        /// <summary>
        /// 综合请求：获取产品下拉数据
        /// </summary>
        /// <returns>型号、规格、供应商、计量单位</returns>
        [HttpGet]
        public async Task<IActionResult> GetProductSelectData()
        {
            var status = BaseStatus.CreateInstance();
            try
            {

                //型号
                var ModelList = await ModelServices.GetAllAsync();


                //规格
                var SpecList = await SpecServices.GetAllAsync();


                //供应商
                var VendorList = await VendorServices.GetAllAsync();



                //计量单位
                var UnitMeasureList = await UnitMeasureServices.GetAllAsync();

                status.Data = new { ModelList, SpecList, VendorList, UnitMeasureList };


            }
            catch (Exception ex)
            {
                status.Code = -1;
                status.Msg = "服务器异常，请稍后重试！";
                //写日志
                await LogHelper.WriteErrorLog("物料产品-分页获取", ex, HttpContext);
            }
            return Ok(status);
        }



        /// <summary>
        /// 综合请求：获取工作站下拉数据
        /// </summary>
        /// <returns>车间名称,工序名称</returns>
        [HttpGet]
        public async Task<IActionResult> GetWorkstationSelectData()
        {
            var status = BaseStatus.CreateInstance();
            try
            {
                //车间
                var WorkshopList = await WorkshopServices.GetAllAsync();
                var ProProcessList = await ProProcess.GetAllAsync();




                status.Data = new { WorkshopList, ProProcessList };


            }
            catch (Exception ex)
            {
                status.Code = -1;
                status.Msg = "服务器异常，请稍后重试！";
                //写日志
                await LogHelper.WriteErrorLog("工作站-分页获取", ex, HttpContext);
            }
            return Ok(status);
        }



        /// <summary>
        /// 综合请求：获取报价单下拉数据
        /// </summary>
        /// <returns>车间名称,工序名称</returns>
        [HttpGet]
        public async Task<IActionResult> GetOrderQuoteSelectData()
        {
            var status = BaseStatus.CreateInstance();
            try
            {
                //客户
                var ClientList = await ClientServices.GetAllAsync();
                //员工
                var EmployeesList = await EmployeesServices.GetAllAsync();
                //仓库
                var WarehouseList = await WarehouseServices.GetAllAsync();




                status.Data = new { ClientList, EmployeesList, WarehouseList };


            }
            catch (Exception ex)
            {
                status.Code = -1;
                status.Msg = "服务器异常，请稍后重试！";
                //写日志
                await LogHelper.WriteErrorLog("报价单-分页获取", ex, HttpContext);
            }
            return Ok(status);
        }




        /// <summary>
        /// 综合请求：获取退货单下拉数据
        /// </summary>
        /// <returns>车间名称,工序名称</returns>
        [HttpGet]
        public async Task<IActionResult> GetOrderReturnSelectData()
        {
            var status = BaseStatus.CreateInstance();
            try
            {
                //客户
                var ClientList = await ClientServices.GetAllAsync();
                //仓库
                var WarehouseList = await WarehouseServices.GetAllAsync();




                status.Data = new { ClientList, WarehouseList };


            }
            catch (Exception ex)
            {
                status.Code = -1;
                status.Msg = "服务器异常，请稍后重试！";
                //写日志
                await LogHelper.WriteErrorLog("退货单-分页获取", ex, HttpContext);
            }
            return Ok(status);
        }

        /// <summary>
        /// 综合请求：获取退货单下拉数据
        /// </summary>
        /// <returns>供应商仓库,工序名称</returns>
        [HttpGet]
        public async Task<IActionResult> GetOrderPoSelectData()
        {
            var status = BaseStatus.CreateInstance();
            try
            {
                //供应商
                var VendorList = await VendorServices.GetAllAsync();
                //仓库
                var WarehouseList = await WarehouseServices.GetAllAsync();




                status.Data = new { VendorList, WarehouseList };


            }
            catch (Exception ex)
            {
                status.Code = -1;
                status.Msg = "服务器异常，请稍后重试！";
                //写日志
                await LogHelper.WriteErrorLog("退货单-分页获取", ex, HttpContext);
            }
            return Ok(status);
        }
    }
}
